<script type="text/javascript" src="../js/jquery-easyui-1.3.5/jquery.min.js" charset="UTF-8"></script>
 <script type="text/javascript" src="../js/jquery-easyui-1.3.5/jquery.easyui.min.js" charset="UTF-8"></script>
 <link rel="stylesheet" href="../js/jquery-easyui-1.3.5/themes/default/easyui.css" type="text/css"></link>
 <link rel="stylesheet" href="../js/jquery-easyui-1.3.5/themes/icon.css" type="text/css"></link>
 <link rel="stylesheet" href="../css/main.css" type="text/css"></link>
 <script type="text/javascript" src="../js/mine.js"></script>
 <script type="text/javascript" src="../js/jquery-easyui-1.3.5/locale/easyui-lang-zh_CN.js" charset="UTF-8"></script>
	 
<script type="text/javascript" charset="UTF-8">
	var studentProjectDatagrid;
	var studentProjectLayout;
	var studentProjectForm;
	var projectDetailDialog;
	$(function(){
		studentProjectForm = $('#studentProjectForm').form();
		studentProjectLayout = $('#studentProjectLayout').layout();
		studentProjectDatagrid = $('#studentProjectDatagrid').datagrid({
			url:'../servlet/GetSProjectServlet',
			//iconCls:'icon-save',
			fitColumns:true,
			nowrap:false,
			striped:true,
			idField:'pno',
			//rownumbers:true,
			pagination:true,
			pageSize:10,
			pageList:[10,20,30],
			fit:true,
			border:false,
			sortName:'stime',
			sortOrder:'desc',
			columns:[[ {
				title:'项目编号',
				field:'pno',
				//sortable:true,
				checkbox:true,
			},{
				title:'项目名称',
				field:'pname',
				width:80,
				sortable:true,
				formatter: function(value,rowData,rowIndex){
		            return '<a href="javascript:void(0);" onclick="showProjectDetail(' + rowIndex + ');" style="text-decoration: none;">'+value+'</a>';
		     	}  
			},{
				title:'发布者',
				field:'pubname',
				width:40
			},{
				title:'创建时间',
				field:'stime',
				width:70,
				sortable:true
			},{
				title:'截止时间',
				field:'etime',
				width:70,
				sortable:true
			},{
				title:'项目状态',
				field:'progress',
				sortable:true,
				width:40,
				formatter: function(value,rowData,rowIndex){
					if(value == '1') {
						return '已完成';
					} else {
						return '进行中';
					}
		     	} 
			},{
				title:'我的状态',
				field:'stage',
				width:45,
				formatter: function(value,rowData,rowIndex){
					if(value == 'todo') {
						return '待接受';
					} else if(value == 'doing') {
						return '进行中';
					} else {
						return '已完成';
					}
		     	}
			},{
				title:'讨论区',
				field:'discuss',
				width:50,
				formatter: function(value,rowData,rowIndex){
		            return '<a href="javascript:void(0);" onclick="showDiscuss(' + rowIndex + ');">'+ value +'</a>';
		     	}  
			},{
				title:'成果区',
				field:'show',
				width:50,
				formatter: function(value,rowData,rowIndex){
					 return '<a href="javascript:void(0);" onclick="showAchieve(' + rowIndex + ');">' + value +'</a>';
		     	}  
			},{
				title:'操作',
				field:'operate',
				width:45,
				formatter: function(value,rowData,rowIndex){
					var action = -1;
					if(value == '接受') {
						action = 1;
					} else {
						action = 2;
					} 
					return '<a href="javascript:void(0);" onclick="changeStage('+ action +', ' + rowData.pno + ');">' + value +'</a>';
		     	}
			}]],
			toolbar:[{
				text:'取消',
				iconCls:'icon-undo',
				handler:function(){
					studentProjectDatagrid.datagrid('unselectAll');
					studentProjectDatagrid.datagrid('rejectChanges');
				}
			},'-',{
				text:'刷新',
				iconCls:'icon-reload',
				handler:function(){
					studentProjectDatagrid.datagrid('unselectAll');
					studentProjectDatagrid.datagrid('rejectChanges');
					studentProjectDatagrid.datagrid('load',{});
				}
			},'-']
		});
		$('#progress').combobox({
			data:[{
				"id":"all",
				"text":"全部",
			},{
				"id":"0",
				"text":"进行中"
			},{
				"id":"1",
				"text":"已完成",
			}],
			valueField:'id',
			textField:'text',
			editable:false
		});
		
	});
	
	showDiscuss = function(i) {
		var rows = studentProjectDatagrid.datagrid('getRows');
		console.info(rows[i]);
		
		var menuTab = parent.$('#menuTab', parent.document).tabs();//得到tabs对象
		var tabText = '讨论区_' + rows[i].pname;
		var tabUrl = 'teacher/discuss.jsp?pno=' + rows[i].pno;
		//console.info(menuTab);
		if(menuTab.tabs('exists', tabText)) {
			menuTab.tabs('select', tabText);
		} else {
			menuTab.tabs('add',{
				title: tabText,
				closable:true,
				//content:tabText
				content:'<iframe src="'+ tabUrl +'" frameborder="0" style="border:0;width:100%;height:100%;"></iframe>'
			});
		}
		
	}
	
	showAchieve = function(i) {
		
		var rows = studentProjectDatagrid.datagrid('getRows');
		
		var menuTab = parent.$('#menuTab', parent.document).tabs();//得到tabs对象
		var tabText = '成果区_' + rows[i].pname;
		var tabUrl = 'teacher/achivement.jsp?pno=' + rows[i].pno;
		//console.info(menuTab);
		if(menuTab.tabs('exists', tabText)) {
			menuTab.tabs('select', tabText);
		} else {
			menuTab.tabs('add',{
				title: tabText,
				closable:true,
				//content:tabText
				content:'<iframe src="'+ tabUrl +'" frameborder="0" style="border:0;width:100%;height:100%;"></iframe>'
			});
		}
		
	}
	
	showProjectDetail = function(i) {
		var rows = studentProjectDatagrid.datagrid('getRows');
		var title = '项目详情_' + rows[i].pname;
		console.info(title);
		projectDetailDialog = parent.$('#projectDetailDialog', parent.document).dialog({
			title:title,
			modal:true,
			collapsible:false,
			showHeader:false,
			width:650,
			height:550,
			href:'teacher/projectDetail.jsp?pno=' + rows[i].pno + '&pname=' + rows[i].pname
		});
		
		projectDetailDialog.dialog('open');
	}
	
	changeStage = function(action, pno) {
		console.info(action);
		if(action != null && action != -1) {
			var msg;
			if(action == 1) {
				msg = '确定接受任务吗?';
			} else {
				msg = '确定完成任务吗?';
			}
			$.messager.confirm('提示',msg,function(b) {
				if(b) {
					$.ajax({
						url:'../servlet/ChangeStageServlet',
						data:{
							action:action,
							pno:pno
						},
						type:'post',
						dataType:'json',
						success:function(r) {
							if(r && r.success) {
								studentProjectDatagrid.datagrid('acceptChanges');
								studentProjectDatagrid.datagrid('load');
								studentProjectDatagrid.datagrid('unselectAll');
								studentProjectDatagrid.datagrid('rejectChanges');
								//console.info(studentProjectDatagrid.datagrid('getSelections'));
								$.messager.show({
									title:'提示',
									msg:'改变状态成功'
								});
							} else {
								$.messager.alert('出错啦','改变状态失败.','error');
							}
						}
					});
				}
		});
		} else {
			$.messager.alert('出错啦','改变状态失败.','error');
		}
	}
	
	searchStudentProject = function() {
		console.info(serializeObject(studentProjectForm));
		studentProjectDatagrid.datagrid('load',serializeObject(studentProjectForm));
		studentProjectDatagrid.datagrid('unselectAll');
		studentProjectDatagrid.datagrid('rejectChanges');
	}

	cleanStudentProject = function() {
		studentProjectDatagrid.datagrid('load',{});
		studentProjectForm.find('input').val('');
		studentProjectDatagrid.datagrid('unselectAll');
		studentProjectDatagrid.datagrid('rejectChanges');
	}
	
	
</script>

<div id="studentProjectLayout" fit="true" border="false" >
		<div region="north" border="false" split="false" title="查询" style="margin:0 auto;height:81px;" >
			<form id="studentProjectForm"  class="datagrid-toolbar" style="margin:0 auto;">
				<table>
					<tr>
						<td><b>项目名称</b><input type="text" name="pname" id="pname"/></td>
						<td ><b>创建时间</b><input type="text" name="stimef" id="stimef" class="easyui-datetimebox" />-</td>
						<td><input type="text" name="stimet" id="stimet" class="easyui-datetimebox" /></td>
					</tr>
					<tr>
						<td><b>项目进度</b><input type="text" name="progress" id="progress"/></td>
						<td><b>截止时间</b><input type="text" name="etimef" id="etimef" class="easyui-datetimebox" />-</td>
						<td><input type="text" name="etimet" id="etimet" class="easyui-datetimebox" /></td>
						<td>
							<a href="javascript:void(0);" class="easyui-linkbutton"  iconCls="icon-search" pain="false" onclick="searchStudentProject();" ></a>
						</td>
						<td>
							<a href="javascript:void(0);" class="easyui-linkbutton"  pain="false" onclick="cleanStudentProject();" >清空</a>
						</td>
					</tr>
					<!-- <tr>
						<td><b>&nbsp;&nbsp;&nbsp;&nbsp;发布者</b><input type="text" name="pubname"/></td>
					</tr> -->
				</table>
			</form>
			</div>
	<div region="center" border="false" >
		<table id="studentProjectDatagrid"></table>
	</div>
</div>

	
